Z algorithm - Linear time Pattern SearchingΒΆ
What is Z Array?
For a string str[0..n-1], Z array is of same length as string.
An element Z[i] of Z array stores length of the longest substring
starting from str[i] which is also a prefix of str[0..n-1].
The first entry of Z array is meaning less as complete string
is always prefix of itself.
See: https://www.geeksforgeeks.org/z-algorithm-linear-time-pattern-searching-algorithm/
http://www.utdallas.edu/~besp/demo/John2010/z-algorithm.htm